import 'package:hitutor/Util/Global.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hitutor/Util/MyColor.dart';

class Button extends StatelessWidget {
  Button(this.text,
      {this.onTap, this.bgColor, this.fontColor, this.width, this.height, this.radius, this.fontSize, this.isBorderBg, this.margin});

  String text = "";
  void Function()? onTap;
  Color? bgColor;
  Color? fontColor;
  EdgeInsetsGeometry? margin;
  double? width;
  double? height;
  double? radius;
  double? fontSize;
  bool? isBorderBg = false;

  @override
  Widget build(BuildContext context) {
    isBorderBg = isBorderBg ?? false;
    return GestureDetector(
      onTap: onTap,
      child: Container(
        height: height ?? 44,
        width: width ?? 220,
        margin: margin,
        alignment: Alignment.center,
        decoration: isBorderBg!
            ? BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(radius ?? 4)),
                border: Border.all(width: 1, color: bgColor ?? MyColor.BlueLow))
            : BoxDecoration(color: bgColor ?? MyColor.BlueLow, borderRadius: BorderRadius.all(Radius.circular(radius ?? 4))),
        child: Text(text,
            style: TextStyle(
                // fontWeight: FontWeight.bold,
                color: fontColor != null ? fontColor : (isBorderBg! ? bgColor ?? MyColor.Green : Color(0xFFFFFFFF)),
                fontSize: fontSize ?? 14)),
      ),
    );
  }
}

class RedBtn extends StatelessWidget {
  String text = "";
  void Function()? onTap;
  EdgeInsetsGeometry? margin;
  double? radius;
  double? height;

  RedBtn(this.text, {this.onTap, this.margin,this.height,this.radius});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        height: height??44,
        width: double.infinity,
        margin: margin,
        alignment: Alignment.center,
        decoration: BoxDecoration(
            gradient: LinearGradient(
                //渐变位置
                begin: Alignment.topCenter, //右上
                end: Alignment.bottomCenter, //左下
                stops: [0.0, 1.0], //[渐变起始点, 渐变结束点]
                colors: [Color(0xFFD04759), Color(0xFFA5051A)]),
            borderRadius: BorderRadius.all(Radius.circular(radius??8)),
            boxShadow: [Global.getShadow(MyColor.Red)]),
        child: Text(text, style: TextStyle(fontWeight: FontWeight.bold, color: Color(0xFFFFFFFF), fontSize: 16)),
      ),
    );
  }
}

class TextBtn extends StatelessWidget {
  TextBtn(this.text, {this.onTap, this.height, this.width, this.alignment, this.margin,this.style});

  String text = "";
  void Function()? onTap;
  TextStyle? style;
  double? height;
  double? width;
  EdgeInsetsGeometry? margin;
  AlignmentGeometry? alignment;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      child: Container(
        margin: margin,
        height: height,
        width: width,
        alignment: alignment ?? Alignment.center,
        child: Text(text,maxLines: 1,style: style),
      ),
      onTap: onTap,
    );
  }
}
